<?php

$object = new FamigliaProdotti();
$objectDao = new FamigliaProdottiDao();

$pg="famiglia_prodotti";
$smarty->Assign('pg',$pg);

$smarty->Assign("list", $objectDao->loadAll($connection));
if ( isset ($_GET['ajax']) && $_GET['ajax'] == "on")
{
	
	if (isset($_GET['action']))
   	{
   		$smarty->Assign('action', $_GET['action']);
		
		$toprightmenu = $smarty->fetch('ajax/toprightmenu.tpl');
		$toprightmenu = str_replace("\n", " ", $toprightmenu);		
		$smarty->Assign('toprightmenu',$toprightmenu);
		
   		switch ($_GET['action']) {
   			
			
			case 'list':
				if(isset($_POST['submitadd'])){
					$nome = htmlentities($_POST['nome']);
					$descrizione = htmlentities($_POST['descrizione']);
					
					
					$object = new FamigliaProdotti();
					$object->setNome($nome);
					$object->setDescrizione($descrizione);
					$object->setVisibile(1);
					$object->setPeso(4);
					$objectDao->create($connection, $object);
					
					$smarty->Assign("list", $objectDao->loadAll($connection));
				}
				if(isset($_POST['submitmodify'])){
					$id = $_POST['id'];
					$nome = htmlentities($_POST['nome']);
					$descrizione = htmlentities($_POST['descrizione']);
					
					
					$object = new FamigliaProdotti();
					$object->setId($id);
					$object->setNome($nome);
					$object->setDescrizione($descrizione);
					$object->setVisibile(1);
					$object->setPeso(4);
					$objectDao->save($connection, $object);
					
					$smarty->Assign("list", $objectDao->loadAll($connection));
				}
				
				$breadCrumb = $smarty->fetch('ajax/breadcrumb.tpl');
				$breadCrumb = str_replace("\n", " ", $breadCrumb);
				$smarty->Assign('breadCrumb',$breadCrumb);
					
				$smarty->display('ajax/famiglia_prodotti.tpl');
					
				
				
				
			;
			break;
			
   			
   			case 'visible':
				
				$smarty->Assign('action', 'list');
				$breadCrumb = $smarty->fetch('ajax/breadcrumb.tpl');
				$breadCrumb = str_replace("\n", " ", $breadCrumb);
				$smarty->Assign('breadCrumb',$breadCrumb);
				
				$toprightmenu = $smarty->fetch('ajax/toprightmenu.tpl');
				$toprightmenu = str_replace("\n", " ", $toprightmenu);		
				$smarty->Assign('toprightmenu',$toprightmenu);
				
   				
				$object = $objectDao->getObject($connection, $_GET['id']);
				$object->setVisibile($_GET['visible']);
				$objectDao->save($connection, $object);
				$smarty->Assign("list", $objectDao->loadAll($connection));
				$smarty->display('ajax/famiglia_prodotti.tpl');
				
   			break;

   			case 'add':
				$breadCrumb = $smarty->fetch('ajax/breadcrumb.tpl');
				$breadCrumb = str_replace("\n", " ", $breadCrumb);
				$smarty->Assign('breadCrumb',$breadCrumb);
				
				$smarty->display('ajax/famiglia_prodotti.tpl');
   				
   			break;
			
			case 'delete':
				
				$smarty->Assign('action', 'list');
				$toprightmenu = $smarty->fetch('ajax/toprightmenu.tpl');
				$toprightmenu = str_replace("\n", " ", $toprightmenu);		
				$smarty->Assign('toprightmenu',$toprightmenu);
				
				$object = $objectDao->getObject($connection, $_GET['id']);
				$objectDao->delete($connection, $object);
				$smarty->Assign("list", $objectDao->loadAll($connection));
				$smarty->display('ajax/famiglia_prodotti.tpl');

			break;
			
			
			case 'modify':
				$breadCrumb = $smarty->fetch('ajax/breadcrumb.tpl');
				$breadCrumb = str_replace("\n", " ", $breadCrumb);
				$smarty->Assign('breadCrumb',$breadCrumb);
				
				$object = $objectDao->getObject($connection, $_GET['id']);
				$smarty->Assign('object',$object);
				
				$smarty->display('ajax/famiglia_prodotti.tpl');

			break;
				
			
   			
   			default:
   				;
   			break;
   		}
	
   	}
	
}
?>